|
In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method declared in the type definition.〔(【引用サイトリンク】title=Extension Methods )〕 Eric Lippert, a principal developer on the C# compiler team, says "Extension methods certainly are not object-oriented.".〔(【引用サイトリンク】title=The Future of C#, Part Two - Fabulous Adventures In Coding )〕 ==Support in programming languages== Extension methods are features of numerous languages including C#, Gosu, Javascript, Oxygene, Ruby, Smalltalk and Visual Basic.NET. In VB.NET and Oxygene, they are recognized by the presence of the " extension " keyword or attribute. In C# they're implemented as static methods in static classes, with the first argument being of extended class and preceded by "this" keyword. In Smalltalk, any code can add a method to any class at any time, by sending a method creation message (such as methodsFor: ) to the class the user wants to extend. The Smalltalk method category is conventionally named after the package that provides the extension, surrounded by asterisks. For example, when Etoys application code extends classes in the core library, the added methods are put in the category.In Ruby, like Smalltalk, there is no special language feature for extension, as Ruby allows classes to be re-opened at any time with the class keyword, in this case to add new methods. The Ruby community often describes an extension method as a kind of monkey patch.In Swift, the extension keyword marks a class-like construct that allows the addition of methods, constructors, and fields to an existing class, including the ability to implement a new interface/protocol to the existing class.抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「extension method」の詳細全文を読む スポンサード リンク
|